package org.bambrikii.site.base.business.managers;

import org.bambrikii.site.base.business.managers.core.ManagerException;
import org.bambrikii.site.base.persistence.IConnector;
import org.bambrikii.site.base.persistence.PersistenceException;

public class ConnectionManager {
	private IConnector connector;

	public ConnectionManager() {
	}

	public ConnectionManager(IConnector connector) {
		this.connector = connector;
	}

	public IConnector getPersistenceConnector() {
		return connector;
	}

	public void setPersistenceConnector(IConnector connector) {
		this.connector = connector;
	}

	public void open() {
		connector.openSession();
	}

	public void close() {
		connector.closeSession();
		connector = null;
	}

	public void begin() throws ManagerException {
		try {
			connector.beginTransaction();
		} catch (PersistenceException ex) {
			throw new ManagerException("Cannot begin transaction", ex);
		}
	}

	public void commit() {
		connector.commitTransaction();
	}

	public void rollback() {
		connector.rollbackTransaction();
	}

}
